package day01;

import lombok.SneakyThrows;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

class UDPSendThread implements Runnable{

    private DatagramSocket sendSocket;


    public UDPSendThread(DatagramSocket sendSocket) {
        this.sendSocket = sendSocket;
    }

    @SneakyThrows
    @Override
    public void run() {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true) {
            System.out.println("可以给群里发送数据: ");
            try {
                String msg = br.readLine();
                DatagramPacket packet = new DatagramPacket(msg.getBytes(),
                        msg.getBytes().length, InetAddress.getByName("192.168.0.255"),8090);
                //发送数据
                sendSocket.send(packet);
                if ("886".equals(msg.trim())) {
                    //接受回送的消息
                    break;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

class UDPReceiveThread implements Runnable {

    @Override
    public void run() {

    }
}

public class UDPChatDemo01 {

}
